package com.briup.jz.web.controller;

import com.briup.jz.bean.Category;
import com.briup.jz.bean.Comment;
import com.briup.jz.bean.User;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: jz
 * @description: 评论控制器
 * @author: catmilko
 * @create: 2020-06-12 11:39
 **/


@RestController
@RequestMapping("comment")
@Api(description = "评论管理接口")
public class CommentController {
    @Autowired
    private ICommentService commentService;
    @PostMapping("commit")
    @ApiOperation("提交评论")
    public Message commit(Comment comment){
        commentService.commit(comment);
        return MessageUtil.success("提交成功");}

    @ApiOperation(value = "查询所有评论")
    @GetMapping("findAll")
    public Message findAll(){
        List<Comment> list = commentService.findAll();
        return MessageUtil.success(list);}
    @GetMapping("auditing")//通过
    public Message auditing(long id){
        commentService.deleteById(id);
        return MessageUtil.success("审核成功");

    }

    @GetMapping("refuseauditing")//拒绝
    public Message refuseauditing(long id){
        commentService.deleteById(id);
        return MessageUtil.success("已拒绝审核");}


    @ApiOperation(value = "查询所有评论,级联获得评论")
    @GetMapping("findAllWithChild")
    public List<CommentExtend> findAllWithChild(){
        return commentService.findAllWithChild();
    }

    @ApiOperation(value = "通过id查询评论")
    @GetMapping("selectById")
    public  Comment selectById(Long id){
        return  commentService.selectById(id);
    }


    @ApiOperation(value = "通过id删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id" ,value = "唯一编号", required = true, paramType = "query")
    })
    @GetMapping("deleteById")
    public Message deleteById(long id){
        commentService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}

